package org.zfes.snowier.zbss.xzy.router.user.face;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.zfes.snowier.core.data.DataSet;
import org.zfes.snowier.web.controller.BaseController;
import org.zfes.snowier.zbss.xzy.biz.dto.ImageInfo;
import org.zfes.snowier.zbss.xzy.biz.face.model.Face;
import org.zfes.snowier.zbss.xzy.biz.face.service.IFaceService;
import org.zfes.snowier.zbss.xzy.biz.util.ImageUtil;

import io.swagger.annotations.ApiOperation;

import org.zfes.snowier.core.data.SelectVo;
import org.zfes.snowier.core.util.ZAlert;
import org.zfes.snowier.core.util.ZAssert;
@Controller("org.zfes.snowier.zbss.xzy.router.user.face.FaceController") 
@RequestMapping("/api/user/face")
public class FaceController implements BaseController {

	
	@Autowired
	private IFaceService faceService;
	
	
    @RequestMapping(value="/loadFaceDataSet", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody  Object loadFaceDataSet(@RequestBody Map<String,Object> params){
	    DataSet dataSet=  faceService.loadFaceDataSet(params);
	    return ajaxQuery("dataSet", dataSet);
    }
    
	@ApiOperation(value = "家庭成员人脸采集")
	@RequestMapping(value="/accquisitFace/{userId}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	public  @ResponseBody Object accquisitFace(@PathVariable("userId")Long userId, String faceimg ) {
			  
		return ajaxDoneSuccess("数据操作成功 ");
	}
	@ApiOperation(value = "加载人脸图片")
	@RequestMapping(value = "/loadFacePic/{userId}",produces = MediaType.IMAGE_JPEG_VALUE)
    public @ResponseBody  byte[] loadFacePic(@PathVariable("userId")Long userId) throws IOException{
		  File file = new File("D:/test.jpg");
	      FileInputStream inputStream = new FileInputStream(file);
	      byte[] bytes = new byte[inputStream.available()];
	      inputStream.read(bytes, 0, inputStream.available());
	      return bytes;
    }
	
	@ApiOperation(value = "加载人脸图片")
	@RequestMapping(value = "/loadFacePicBase64/{userId}",produces = MediaType.IMAGE_JPEG_VALUE)
    public @ResponseBody  Object loadFacePicBase64(@PathVariable("userId")Long userId){
		return ajaxDoneSuccess("数据操作成功 ");
    }
	
	@ApiOperation(value = "删除人脸图片")
    @RequestMapping(value="/deleteFace/{userId}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody  Object deleteFace(@PathVariable("userId")Long userId){
		
		return ajaxDoneSuccess("数据操作成功 ");
    }

    public static String getFileType(String fileName) {
        if(fileName!=null && fileName.indexOf(".")>=0) {
            return fileName.substring(fileName.lastIndexOf("."), fileName.length());
        }
        return "";
    }
  
    
}